using System;
using System.Windows.Forms;

namespace Devv.Threeter
{
	public partial class FormHotKey : Form
	{
		#region Properties

		public String HotKey
		{
			get
			{
				return txtHotKey.Text;
			}
		}

		#endregion

		#region Main methods

		public FormHotKey()
		{
			InitializeComponent();
		}

		private void FormHotKey_Load(Object sender, EventArgs e)
		{
			BringToFront();
		}

		private void FormHotKey_KeyDown(Object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				DialogResult = DialogResult.Cancel;
			}
			else
			{
				const String cancelKeys = "-CONTROLKEY-ALTKEY-SHIFTKEY-MENU-"; 
				String key = Enum.GetName(typeof(Keys), e.KeyCode).ToUpper();

				if (cancelKeys.Contains("-" + key))
				{
					e.Handled = false;
				}
				else if (e.Alt && e.Control)
				{
					txtHotKey.Text = "ALT + CTRL + " + key;
				}
				else if (e.Alt && e.Shift)
				{
					txtHotKey.Text = "ALT + SHIFT + " + key;
				}
				else if (e.Control && e.Shift)
				{
					txtHotKey.Text = "CTRL +SHIFT + " + key;
				}
				else if (e.Alt)
				{
					txtHotKey.Text = "ALT + " + key;
				}
				else if (e.Control)
				{
					txtHotKey.Text = "CTRL + " + key;
				}
				else if (e.Shift)
				{
					txtHotKey.Text = "SHIFT + " + key;
				}
				else
				{
					txtHotKey.Text = key;
				}

				txtHotKey.Focus();
			}
		}

		private void ButSetHotKey_Click(Object sender, EventArgs e)
		{
			if (txtHotKey.Text.Length > 0)
			{
				DialogResult = DialogResult.OK;
			}
			else
			{
				DialogResult = DialogResult.Cancel;
			}
		}

		#endregion
	}
}